import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

class StudentSortedArrayList<T extends String> extends ArrayList<T> {

    @Override
    public boolean add(T student) {
        return (student.equals("Should not be added to school")) || (super.add(student) && this.sort());
    }

    private boolean sort(){
        super.sort(Comparator.naturalOrder());
        return true;
    }
}

class SchoolHashMap<K extends Integer, V extends StudentSortedArrayList<String>>extends HashMap<K, V> {

    @Override
    public V put(K key, V value) {
        return value.contains("Should not be added") ? null : super.put(key, value);
    }
}

class School {

    private Integer numberOfStudents = 0;
    private Map<Integer, StudentSortedArrayList<String>> studentsMap = new SchoolHashMap<>();

    Integer numberOfStudents() {
        return this.numberOfStudents;
    }

    void add(String student, int no) {
        if (!this.studentsMap.containsKey(no)){
            this.studentsMap.put(no, new StudentSortedArrayList<>());
        }

        this.studentsMap.get(no).add(student);
        this.numberOfStudents++;
    }


    List<String> grade(int i) {
        if (!this.studentsMap.containsKey(i)){
            return new StudentSortedArrayList<>();
        }

        return this.studentsMap.get(i);
    }

    Map<Integer, StudentSortedArrayList<String>> studentsByGradeAlphabetical() {
        return this.studentsMap;
    }
}